/*
 *  (C) Copyright 2008 Insula Tecnologia da Informacao Ltda.
 * 
 *  This file is part of Vulcano.
 *
 *  Vulcano is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Vulcano is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Vulcano.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.openinsula.vulcano.orm.dao.hibernate;

import static org.junit.Assert.*;

import java.util.Arrays;

import org.junit.Test;
import org.openinsula.vulcano.orm.dao.query.DaoQuery;
import org.openinsula.vulcano.orm.dao.query.builder.DaoQueryBuilder;
import org.openinsula.vulcano.orm.dao.query.spec.SpecFactory;
import org.openinsula.vulcano.orm.jpa.entity.SimpleEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

@ContextConfiguration(locations = { "/test-context-weaver.xml", "classpath*:META-INF/*-context.xml" })
public class HibernateDaoImplTestCase extends AbstractTransactionalJUnit4SpringContextTests {

	@Autowired
	private HibernateDaoImpl dao;

	// @Test
	// public void testClear() {
	// }
	//
	// @Test
	// public void testDelete() {
	// }
	//
	// @Test
	// public void testDeleteAll() {
	// }
	//
	// @Test
	// public void testFind() {
	// }
	//
	// @Test
	// public void testFindById() {
	// }
	//
	// @Test
	// public void testFlush() {
	// }

	public <V> V teste() {
		return null;
	}

	@Test
	public void testListAll() {
		int totalEntities = dao.listAll(SimpleEntity.class).size();

		SimpleEntity[] entities = new SimpleEntity[] { new SimpleEntity(), new SimpleEntity(), new SimpleEntity(),
				new SimpleEntity(), new SimpleEntity() };

		dao.saveAll(Arrays.asList(entities));
		dao.flush();

		totalEntities += 5;

		assertTrue(dao.listAll(SimpleEntity.class).size() == totalEntities);
	}

	@Test
	public void testFindDaoQuery() {
		dao.deleteAll(SimpleEntity.class);

		SimpleEntity simpleEntity = new SimpleEntity();
		simpleEntity.setName("John Doe");
		dao.save(simpleEntity);
		dao.flush();

		DaoQuery daoQuery = new DaoQueryBuilder().select().from(SimpleEntity.class).where(
				SpecFactory.eq("name", "John Doe")).getDaoQuery();

		SimpleEntity simpleEntity2 = dao.<SimpleEntity> findUnique(daoQuery);
		assertEquals(simpleEntity.getName(), simpleEntity2.getName());
	}

	// @Test
	// public void testReattach() {
	// }
	//
	// @Test
	// public void testRefresh() {
	// }
	//
	// @Test
	// public void testReplicate() {
	// }
	//
	// @Test
	// public void testSave() {
	// }
	//
	// @Test
	// public void testSaveAll() {
	// }
	//
	// @Test
	// public void testUniqueSearch() {
	// }
	
}
